from flask import request
from flask_restful import Resource

from database import Database


class DeleteStack(Resource):
    def delete(self):
        db = Database()
        data = request.json
        stackId = data.get('stackId')

        query = "SELECT * FROM stack WHERE stackId = %s"
        db.execute_query(query, (stackId,))
        stack = db.cursor.fetchone()

        if stack is None:
            return {"message": "Stack not found"}, 404

        query = "DELETE FROM stack WHERE stackId = %s"
        db.execute_query(query, (stackId,))
        db.connection.commit()

        return {"message": "Stack deleted successfully"}, 200
